home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / gfx / nsMargin.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  5KB  |  124 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef NSMARGIN_H
  39. #define NSMARGIN_H
  40.  
  41. #include "nsCoord.h"
  42. #include "gfxCore.h"
  43.  
  44. struct nsMargin {
  45.   nscoord top, right, bottom, left;
  46.  
  47.   // Constructors
  48.   nsMargin() {}
  49.   nsMargin(const nsMargin& aMargin) {*this = aMargin;}
  50.   nsMargin(nscoord aLeft,  nscoord aTop,
  51.            nscoord aRight, nscoord aBottom) {left = aLeft; top = aTop;
  52.                                              right = aRight; bottom = aBottom;}
  53.  
  54.   void SizeTo(nscoord aLeft,  nscoord aTop,
  55.               nscoord aRight, nscoord aBottom) {left = aLeft; top = aTop;
  56.                                                 right = aRight; bottom = aBottom;}
  57.   void SizeBy(nscoord aLeft, nscoord  aTop,
  58.               nscoord aRight, nscoord aBottom) {left += aLeft; top += aTop;
  59.                                                 right += aRight; bottom += aBottom;}
  60.  
  61.   nscoord LeftRight() const { return left + right; }
  62.   nscoord TopBottom() const { return top + bottom; }
  63.  
  64. #if (NS_SIDE_TOP == 0) && (NS_SIDE_RIGHT == 1) && (NS_SIDE_BOTTOM == 2) && (NS_SIDE_LEFT == 3)
  65.   nscoord& side(PRUint8 aSide) {
  66.     NS_PRECONDITION(aSide <= NS_SIDE_LEFT, "Out of range side");
  67.     return *(&top + aSide);
  68.   }    
  69.  
  70.   nscoord side(PRUint8 aSide) const {
  71.     NS_PRECONDITION(aSide <= NS_SIDE_LEFT, "Out of range side");
  72.     return *(&top + aSide);
  73.   }    
  74. #else
  75. #error "Somebody changed the side constants."
  76. #endif
  77.  
  78.   // Overloaded operators. Note that '=' isn't defined so we'll get the
  79.   // compiler generated default assignment operator
  80.   PRBool operator==(const nsMargin& aMargin) const {
  81.     return (PRBool) ((left == aMargin.left) && (top == aMargin.top) &&
  82.                      (right == aMargin.right) && (bottom == aMargin.bottom));
  83.   }
  84.   PRBool operator!=(const nsMargin& aMargin) const {
  85.     return (PRBool) ((left != aMargin.left) || (top != aMargin.top) ||
  86.                      (right != aMargin.right) || (bottom != aMargin.bottom));
  87.   }
  88.   nsMargin operator+(const nsMargin& aMargin) const {
  89.     return nsMargin(left + aMargin.left, top + aMargin.top,
  90.                     right + aMargin.right, bottom + aMargin.bottom);
  91.   }
  92.   nsMargin operator-(const nsMargin& aMargin) const {
  93.     return nsMargin(left - aMargin.left, top - aMargin.top,
  94.                     right - aMargin.right, bottom - aMargin.bottom);
  95.   }
  96.   nsMargin& operator+=(const nsMargin& aMargin) {left += aMargin.left;
  97.                                                  top += aMargin.top;
  98.                                                  right += aMargin.right;
  99.                                                  bottom += aMargin.bottom;
  100.                                                  return *this;}
  101.   nsMargin& operator-=(const nsMargin& aMargin) {left -= aMargin.left;
  102.                                                  top -= aMargin.top;
  103.                                                  right -= aMargin.right;
  104.                                                  bottom -= aMargin.bottom;
  105.                                                  return *this;}
  106. };
  107.  
  108. #ifdef NS_COORD_IS_FLOAT
  109. struct nsIntMargin {
  110.   PRInt32 top, right, bottom, left;
  111.  
  112.   // Constructors
  113.   nsIntMargin() {}
  114.   nsIntMargin(const nsIntMargin& aMargin) {*this = aMargin;}
  115.   nsIntMargin(PRInt32 aLeft,  PRInt32 aTop,
  116.               PRInt32 aRight, PRInt32 aBottom) {left = aLeft; top = aTop;
  117.                                                 right = aRight; bottom = aBottom;}
  118. };
  119. #else
  120. typedef nsMargin nsIntMargin;
  121. #endif
  122.  
  123. #endif /* NSMARGIN_H */
  124.